import cv2


# 灰度转换
def to_gray(param_img):
    if len(param_img.shape) == 3:
        gray = cv2.cvtColor(param_img, cv2.COLOR_BGR2GRAY)
        return gray
    else:
        return param_img


def to_resize(param_img, crop_k=2):
    _h, _w = get_HW(param_img)
    return cv2.resize(param_img, (_w // crop_k, _h // crop_k))


# 获取高宽
def get_HW(param_img):
    if type(param_img) == type(None):
        return 0, 0
    h, w = param_img.shape[0], param_img.shape[1]
    return h, w


# 显示图像
def get_showimage(param_img, win_name="image", resize=False):
    cv2.namedWindow(win_name)
    if resize:
        cv2.resizeWindow(win_name, 400, 400)
    cv2.imshow(win_name, param_img)
    cv2.waitKey(0)
    cv2.destroyWindow(win_name)
